package com.hejia.bulbul.controller;

import java.util.List;

import com.hejia.alauda.entity.Parameter;
import com.hejia.alauda.service.ConfigureService;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 
 * 客服服务参数设置
 *
 *
 * Created by showone on 2014 上午10:49:51.
 *
 * @Copyright: 2014 www.hejiajinrong.com All rights reserved.
 */
@Controller
@RequestMapping("setting/customer")
public class SettingCustomerController extends BaseController {

	@Resource
	private ConfigureService parameterService;

	@RequestMapping(value = "list", method = RequestMethod.GET)
	public String list(ModelMap model) {
		List<Parameter> list = parameterService
				.getParameters(Parameter.Category.Customer);

		model.put("list", list);
		return "/setting/customer";
	}

	@RequestMapping(value = "update", method = RequestMethod.POST)
	public String update(HttpServletRequest request, ModelMap model) {
		List<Parameter> list = parameterService
				.getParameters(Parameter.Category.Customer);
		for (int i = 0; i < list.size(); i++) {
			Parameter param = list.get(i);
			param.setValue(request.getParameter(param.getCode()));
			parameterService.updateParameter(param);
		}
		model.put("msg", "修改成功!");
		model.put("status", STATUS_SUCCESS);

		return list(model);
	}
}
